<script>
import {cancelBatch, cancelOrder, deleteBatch, list} from "@/api/order"
export default {
  name: "Order",
  data(){
    return{
      tableData: [],
      tableData1: [],
      status:null,
      type:null,
      orderNo:null,
      orderStatus:null,
      createBy:null,
      createDate:null,
      typeList:[{name:'挂号',value:'0'},{name:'医币充值',value:'1'}],
      statusList:[{name:'已支付',value:'1'},{name:'待支付',value:'0'},{name:'已取消',value:'-1'}],
      currentPage: 1,
      pageSize: 5,
      total: 0,
      currentPage1: 1,
      pageSize1: 10000,
      total1: 0,
      loading: true,
      multipleSelection: [],
      dialogFormVisible: false,
      dialogFormVisible1: false,
      form: {},
      formLabelWidth: '150px',
      title:null,
    }
  },
  created() {
    this.load();
  },
  methods:{
    load() {
      let params={
        orderNo:this.orderNo,
        type:this.type,
        status:this.status,
        createBy:this.createBy,
        createDate:this.createDate,
        currentPage: this.currentPage,
        pageSize: this.pageSize,
      }
      list(params).then(res => {
        this.tableData = res.data.records;
        this.loading = false;
        this.total = res.data.total;
      });
    },
    load1(){
      let params={
        status:this.orderStatus,
        currentPage: this.currentPage1,
        pageSize: this.pageSize1,
      }
      list(params).then(res => {
        this.tableData1 = res.data.records;
        this.total1 = res.data.total;
      });
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.load();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.load();
    },
    handleSizeChange1(val) {
      this.pageSize1 = val;
      this.load1();
    },
    handleCurrentChange1(val) {
      this.currentPage1 = val;
      this.load1();
    },
    reset() {
      this.orderNo=null,
      this.status=null,
      this.type=null,
      this.createBy=null,
      this.createDate=null,
      this.pageSize = 5;
      this.total = 0;
      this.load();
    },
    handleSelectionChange(val) {
      this.multipleSelection = val.map((a) => a.orderNo);
      console.log(this.multipleSelection);
    },
    handleBatchDelete(){
      this.title='批量删除';
      this.orderStatus='2',
      this.load1();
      this.dialogFormVisible=true;
    },
    handleBatchCancel(){
      this.title='批量取消';
      this.orderStatus='0',
          this.load1();
      this.dialogFormVisible=true;
    },
    batchOperation(){
    let orderNos=this.multipleSelection;
    if(this.orderStatus=='2'){
      deleteBatch(orderNos).then(res=>{
        if (res.code == 200) {
          this.$message({
            message: '批量删除成功',
            type: 'success',
            center: true
          });
          this.dialogFormVisible=false;
        } else {
          this.$message({
            center: true,
            message:  res.msg,
            type: 'error'
          });
        }
      })
    }else if(this.orderStatus=='0'){
     cancelBatch(orderNos).then(res=>{
        if (res.code == 200) {
          this.$message({
            message: '批量取消成功',
            type: 'success',
            center: true
          });
          this.dialogFormVisible=false;
        } else {
          this.$message({
            center: true,
            message:  res.msg,
            type: 'error'
          });
        }
      })
    }
    },
    handleDelete(orderNo){

    },
    handleCancel(orderNo){

    },
    headerBg({row,rowIndex}){
      if(rowIndex==0){
        return 'headerBgClass';
      }
    }
  }
}
</script>

<template>
  <div>
    <div class="search">
      <el-input style="width:160px" v-model="orderNo" suffix-icon="el-icon-search" placeholder="请输入订单号" clearable></el-input>
      <el-select v-model="type" class="ml-5" placeholder="请选择订单类型"  clearable>
        <el-option v-for="item in typeList" :key="item.value" :label="item.name" :value="item.value"></el-option>
      </el-select>
      <el-select v-model="status" class="ml-5" placeholder="请选择订单状态"  clearable>
        <el-option v-for="item in statusList" :key="item.value" :label="item.name" :value="item.value"></el-option>
      </el-select>
      <el-input style="width:160px" v-model="createBy" class="ml-5" suffix-icon="el-icon-search" placeholder="请输入下单人" clearable></el-input>
      <el-date-picker type="date" v-model="createDate" format="yyyy年MM月dd日" value-format="yyyy-MM-dd" placeholder="请选择下单日期" class="ml-5" clearable></el-date-picker>
      <el-button type="primary" style="margin-left: 5px" @click="load">搜索</el-button>
      <el-button type="warning" style="margin-left: 5px" @click="reset">重置</el-button>
    </div>
    <div style="margin:10px 0px" class="operation">
        <el-button type="danger" class="ml-5" icon="el-icon-remove-outline" slot="reference" @click="handleBatchDelete">批量删除</el-button>
        <el-button type="warning" class="ml-5" icon="el-icon-circle-close" slot="reference" @click="handleBatchCancel">批量取消</el-button>
      <el-dialog :visible.sync="dialogFormVisible" :title="title" width="50%" center>
        <el-table :data="tableData1"
                  border stripe
                  max-height="550"
                  :header-cell-class-name="headerBg"
                  @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="50px" align="center"></el-table-column>
          <el-table-column prop="id" label="ID" width="55px" align="center">
          </el-table-column>
          <el-table-column prop="orderNo" label="订单号" width="200px" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column  label="订单类型"  align="center">
            <template slot-scope="scope">
              {{scope.row.type=='0'?'挂号':'医币充值'}}
            </template>
          </el-table-column>
          <el-table-column prop="amount" label="订单金额"  align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="createBy" label="下单人"  align="center">
          </el-table-column>
          <el-table-column prop="createTime" label="下单时间"  align="center">
          </el-table-column>
          <el-table-column  label="订单状态"  align="center">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.status=='1'" type="success">已支付</el-tag>
              <el-tag v-else-if="scope.row.status=='0'" type="warning">待支付</el-tag>
              <el-tag v-else type="danger">已取消</el-tag>
            </template>
          </el-table-column>
        </el-table>
        <div style="padding:10px 0px">
          <el-pagination
              @size-change="handleSizeChange1"
              @current-change="handleCurrentChange1"
              :current-page="currentPage"
              :page-sizes="[5, 10, 15, 20]"
              :page-size="pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="total">
          </el-pagination>
          <div slot="footer" class="dialog-footer" style="margin-top: 20px" align="right">
            <el-button type="primary" @click="batchOperation">{{title}}</el-button>
            <el-button @click="dialogFormVisible= false">取 消</el-button>
          </div>
        </div>
      </el-dialog>
    </div>
  <div class="table">
    <el-table :data="tableData"
              border stripe
              v-loading="loading"
              max-height="550"
              :header-cell-class-name="headerBg"
              element-loading-text="拼命加载中"
              element-loading-spinner="el-icon-loading"
              element-loading-background="rgba(255,225,255, 0.1)"
    >
      <el-table-column prop="id" label="ID" width="55px" align="center">
      </el-table-column>
      <el-table-column prop="orderNo" label="订单号" width="220px" align="center" :show-overflow-tooltip="true">
      </el-table-column>
      <el-table-column  label="订单类型"  align="center">
        <template slot-scope="scope">
          {{scope.row.type=='0'?'挂号':'医币充值'}}
        </template>
      </el-table-column>
      <el-table-column prop="amount" label="订单金额"  align="center" :show-overflow-tooltip="true">
      </el-table-column>
      <el-table-column prop="createBy" label="下单人"  align="center">
      </el-table-column>
      <el-table-column prop="createTime" label="下单时间"  align="center">
      </el-table-column>
      <el-table-column  label="订单状态"  align="center">
        <template slot-scope="scope">
        <el-tag v-if="scope.row.status=='1'" type="success">已支付</el-tag>
        <el-tag v-else-if="scope.row.status=='0'" type="warning">待支付</el-tag>
          <el-tag v-else type="danger">已取消</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="250px">
        <template slot-scope="scope">
          <el-button type="primary" icon="el-icon-tickets">订单详情</el-button>
          <el-popconfirm
              class="ml-5"
              confirm-button-text='确定'
              cancel-button-text='我再想想'
              icon="el-icon-info"
              icon-color="red"
              title="您确定删除吗？"
              v-if="scope.row.status !='0'"
              @confirm="handleDelete(scope.row.orderNo)"
          >
          <el-button type="danger"  icon="el-icon-delete" slot="reference">删除订单</el-button>
          </el-popconfirm>
          <el-popconfirm
              class="ml-5"
              confirm-button-text='确定'
              cancel-button-text='我再想想'
              icon="el-icon-info"
              icon-color="red"
              title="您确定取消吗？"
              v-if="scope.row.status =='0'"
              @confirm="handleCancel(scope.row.orderNo)"
          >
          <el-button type="warning"  icon="el-icon-s-release" slot="reference">取消订单</el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <div style="padding:10px 0px">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </div>
  </div>
  </div>
</template>

<style scoped>
.headerBgClass{
  background-color: #cccccc !important;
}
</style>